// 确认操作
export const useConfirm = (config?: Partial<{ message: string; deep: boolean; callback: Function }>) => {
  const { message = '请确认操作。', deep, callback } = config || {}
  if (deep) {
    return new Promise((ok, err) => {
      const iptValue = ref('')
      const iptError = ref(false)
      Modal.open({
        title: '提示',
        content: () => (
          <>
            <p class='mb-2'>{message}</p>
            <a-input
              v-model={iptValue.value}
              error={iptError.value}
              onFocus={() => (iptError.value = false)}
              placeholder='请在这里输入：“我已确认操作”'
            />
          </>
        ),
        titleAlign: 'start',
        draggable: true,
        onCancel() {
          return Promise.reject('点击了取消')
        },
        async onBeforeOk(done) {
          if (iptValue.value !== '我已确认操作') {
            iptValue.value = ''
            iptError.value = true
            return false
          } else {
            if (callback) await callback()
            done(true)
          }
        },
        onOk() {
          ok('')
        },
      })
    })
  } else {
    return new Promise((ok, err) => {
      Modal.open({
        title: '提示',
        content: message,
        titleAlign: 'start',
        draggable: true,
        onCancel() {
          return Promise.reject('点击了取消')
        },
        onOk() {
          callback && callback()
          ok('')
        },
      })
    })
  }
}
